// pages/getCode/getCode.js
const app = getApp()
const util = require('../../../utils/util.js')
const http = require('../../../utils/http.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    top: '',
    info: '',
    code: 2,
    statusBarHeight: getApp().globalData.statusBarHeight
  },
  //点击复制功能
  getTel(e){
    const code = e.currentTarget.dataset.code;
    let _this = this
    wx.setClipboardData({
      data:code,
       success: function (res) {
        wx.getClipboardData({
          success: function (res) {}})
      }

    })
  },
  //首页分类数据
  getQrCode(data) {
    let _this = this
    http.getRequest('v1/getQrCode', data,
      function (res) {
        _this.setData({
          info: res.data
        })
      },
      function (err) {
        wx.navigateTo({
          url: '/pages/Login/Index/index',
        })
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var Info = wx.getStorageSync('member');
    console.log(Info)
    this.setData({
      Info: Info
    })
    let code = options.code;
    if (code) {
      this.setData({
        code: code
      })
    }
  },
  back: function () {
    
      wx.navigateBack({
        delta: 1,
      })

  },
  //滚动
  scrollTopFun(e) {
    var top = e.detail.scrollTop;
    var that = this;
    that.setData({
      top: top
    })
  },
  //保存图片
  save() {
    let _this = this
    wx.downloadFile({
      url: this.data.info.qrcode_path,
      success: function (res) {

        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: function (dres) {
            _this.toasts.showToast({
              type: 'success',
              title: '已保存',
              duration: 7000,
            })
          },
          fail(res) {
            _this.toastDialog.showDialog('保存失败')
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.toastDialog = this.selectComponent("#toastDialog"); //此处id和页面的 wxml中的id一致
    this.toasts = this.selectComponent('#toasts')
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getQrCode('')
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})